﻿using UnityEngine;
using System;

namespace GameBasic
{
    public static class BasicValue
    {
        public const float TIME_FPS_1 = 1;
        public const float TIME_FPS_2 = 0.5f;
        public const float TIME_FPS_5 = 0.2f;
        public const float TIME_FPS_10 = 0.1f;
        public const float TIME_FPS_16 = 0.0625f;
        public const float TIME_FPS_24 = 0.042f;
        public const float TIME_FPS_30 = 0.033f;

        #region Float Vector
        public static float Zero()
        {
            return 0;
        }

        public static Vector2 Zero2()
        {
            return Vector2.zero;
        }

        public static Vector3 Zero3()
        {
            return Vector3.zero;
        }

        public static float One()
        {
            return 1;
        }

        public static Vector2 One2()
        {
            return Vector2.one;
        }

        public static Vector3 One3()
        {
            return Vector3.one;
        }

        public static Quaternion Identity()
        {
            return Quaternion.identity;
        }
        #endregion

        #region Bool
        public static Func<bool> True => Bool.True;
        public static Func<bool> False => Bool.False;

        public static class Bool
        {
            public readonly static Func<bool> True = IsTrue;
            public readonly static Func<bool> False = IsFalse;

            public static bool IsTrue()
            {
                return true;
            }

            public static bool IsTrue(Func<bool> func)
            {
                return func();
            }

            public static bool IsTrue(params Func<bool>[] funcs)
            {
                foreach (Func<bool> f in funcs)
                    if (!f())
                        return false;
                return true;
            }

            public static bool IsFalse()
            {
                return false;
            }

            public static bool Is(Func<bool> func, bool value)
            {
                return func() == value;
            }

            public static bool All(Func<bool>[] funcs, bool value)
            {
                foreach (Func<bool> f in funcs)
                    if (f() != value)
                        return false;
                return true;
            }

            public static bool Any(Func<bool>[] funcs, bool value)
            {
                foreach (Func<bool> f in funcs)
                    if (f() == value)
                        return true;
                return false;
            }

            public static bool Not(Func<bool>[] funcs, bool value)
            {
                return All(funcs, !value);
            }

            #region Function version
            public static Func<bool> All(params Func<bool>[] funcs)
            {
                return All(true, funcs);
            }

            public static Func<bool> All(bool value, params Func<bool>[] funcs)
            {
                return () => All(funcs, value);
            }

            public static Func<bool> Any(params Func<bool>[] funcs)
            {
                return Any(true, funcs);
            }

            public static Func<bool> Any(bool value, params Func<bool>[] funcs)
            {
                return () => Any(funcs, value);
            }

            public static Func<bool> Not(Func<bool> func)
            {
                return () => !func();
            }

            public static Func<bool> Not(params Func<bool>[] funcs)
            {
                return () => Not(funcs, true);
            }
            #endregion
        }
        #endregion
    }
}